Skip to main content
Version: 4.0

Workflow script is normally used after submitting a to do task. To do task triggers the script to execute and complete the workflow.

info

Write the script in a template service for workflows calling.

Creating Object Service

Add 3 input parameters to represent data involved in workflows.

  • data: JSON data from business form transmitted from the previous task.
{
"name": "Emma",
"sex": "F"
...
}
  • auditData: Branch task information.
ParameterTypeDescription
namestringBranch name
rejectbooleanWhether to reject the branch task
orderintegerBranch code.
  • flowData: Workflow information.
ParameterTypeDescription
processIdstringProcess instance ID
processNamestringProcess name
taskNamestringTo do task name
taskIdstringTo do task ID
userIdstringExecutor ID of the to do task
staffNamestringExecutor name
initiatorIdstringProcess initiator ID
initiatorNamestringProcess initiator name
createTimestringReceive time of the to do task

Writing Service Script

var formDataJson = JSON.parse(data); // JSON data of the form
var auditDataJson = JSON.parse(auditData);
var flowDataJson = JSON.parse(flowData);

var name = auditDataJson.name; //branch task name
var order = auditDataJson.order; //branch task name
var isReject = auditDataJson.reject; //whether to reject the branch task

var taskName = flowDataJson.taskName;//currently submitted task name
var startUser = flowDataJson.initiatorName;//process initiator name
var processId = flowDataJson.processId;//current process instance ID
var taskId = flowDataJson.taskId; //currently submitted task ID

//TODO specific business logic
.....

var result = {
"code": "200", // 200 represents success. Error returns codes other than 200 and 201
"message": "error message"
}
result;